import request from '@/utils/request'

function url(u) {
  const prefix = '/room'
  return `${prefix}${u || ''}`
}

export function findMeetingRoomById(id) {
  return request({
    url: url(`/${id}`),
    method: 'get'
  })
}

export function findMeetingRoomBySize(size) {
  return request({
    url: url(`/size/${size}?size=1000&page=0`),
    method: 'get'
  })
}

/**
 *
 * @param {string} week 以三个字母缩写确定 示例: Mon:周一 Tue：周二
 * @param {int} moring 0:上午 1：下午
 */
export function findMeetingRoomByOpenTime(week, morning) {
  const data = {
    week,
    morning
  }
  return request({
    url: url('/selectbyopentime'),
    method: 'post',
    data: data
  })
}

/* export function findOpenTime() {
  return request({
    url: url('/selecttime'),
    method: 'get'
  })
} */

/**
 * 设置会议室开放时间
 * @param {object} open
 * @param {number} open.opens 上午开启时间
 * @param {number} open.opene 上午关闭时间
 * @param {number} open.openas 下午开启时间
 * @param {number} open.openae 下午关闭时间
 */
/* export function setOpenTime(open) {
  return request({
    url: url('/settime'),
    method: 'post',
    data: open
  })
} */

export function getOpenTime() {
  return request({
    url: `/a/config/opentime`,
    method: 'get'
  })
}

export function setOpenTime(open) {
  const data = {
    k: 'opentime',
    v: open
  }
  return request({
    url: '/a/config',
    method: 'post',
    data: data
  })
}

export function findAllMeetingRoom() {
  return request({
    url: url(),
    method: 'get'
  })
}

/**
 *
 * @param {object} room
 * @param {string} room.id
 * @param {number} room.opentime
 * @param {string} room.size
 * @param {number} room.device
 * @param {number} room.permission
 * @param {number} room.airconditioner
 * @param {number} room.media
 * @param {number} room.floor
 */
export function addMeetingRoom(room) {
  return request({
    url: '/a/room',
    method: 'post',
    data: room
  })
}

export function updateMeetingRoom(room) {
  return request({
    url: '/a/room',
    method: 'post',
    data: room
  })
}

export function deleteMeetingRoom(room) {
  return request({
    url: `/a/room/${room}`,
    method: 'delete'
  })
}
